package com.woniuxy.cloud.depositassembly.listen;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.cloud.depositassembly.config.AppConfig;
import com.woniuxy.cloud.depositassembly.entity.DepositOrder;
import com.woniuxy.cloud.depositassembly.service.DepositOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @author 周川雄
 * @date 2022/1/19 11:32
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = AppConfig.PRODUCER_GROUP, consumerGroup = "${rocketmq.consumer.group}")
public class RocketMQBootListener implements RocketMQListener<Integer> {

    @Resource
    private DepositOrderService service;

    @Override
    public void onMessage(Integer message) {
        log.info("收到消息：{}", message);
        DepositOrder order = service.getOne(new QueryWrapper<DepositOrder>()
                .eq("deposit_order_id", message).eq("order_status", 0));
        if (!StringUtils.isEmpty(order)) {//说明没有支付
            order.setOrderStatus(2);//设置为过期
            order.setOrderMessage("支付超时");
            service.updateById(order);
        }
    }
}
